﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using Newtonsoft.Json;


namespace Bus_proj.website
{
    public partial class Search_Around : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //string[] Around_id;
            //string[] Route_id;
            //string[] Route_source;
            //string[] Route_destination;
            //string[] Time_id;
            //string[] Time_time;
            //string[] Point_id;
            //string[] Point_name;
            //string[] Point_charges;
            //string[] Point_tax;
            //string[] Type_Bus_id;
            //string[] Type_Bus_name;
            string Connection = ConfigurationManager.ConnectionStrings["Bus_proConnectionString"].ConnectionString;
            try
            {
                string select = @"select Table_Around.Around_id,Table_Around.Around_date_chk , Table_Route.Route_id , Table_Route.Route_source , Table_Route.Route_destination ,
		                            Table_Time.Time_id , Table_Time.Time_time , Table_Point.Point_id , Table_Point.Point_name ,Table_Point.Point_charges ,
		                            Table_Point.Point_tax , Table_Type_Bus.Type_Bus_id , Table_Type_Bus.Type_Bus_name
                                    from Table_Around
                                    inner join Table_Route
	                                    on Table_Around.Route_id = Table_Route.Route_id
                                    inner join Table_Time
	                                    on Table_Around.Time_id = Table_Time.Time_id
                                    inner join Table_Type_Bus
	                                    on Table_Around.Type_Bus_id = Table_Type_Bus.Type_Bus_id
                                    inner join Table_Point
	                                    on Table_Route.Route_id = Table_Point.Route_id
                                    where Around_date >= DATEADD(HOUR,24,GETDATE())";
                SqlCommand sqlcomm = new SqlCommand();
                SqlConnection sqlconn = new SqlConnection(Connection);
                SqlDataAdapter da = new SqlDataAdapter(select, sqlconn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count <= 0)
                {
                    Response.Write(0);
                }
                else
                {
                    string json = JsonConvert.SerializeObject(dt, Formatting.Indented);
                    Response.Write(json);                    
                }
            }
            catch (Exception)
            {


            }
        }
    }
}